package com.dailywork.basepro.thread.concurrent;

import java.util.TimerTask;
import java.util.concurrent.Executors;
import java.util.concurrent.ScheduledExecutorService;
import java.util.concurrent.TimeUnit;

/**
 * 多任务调度
 *
 * @author think
 * @since 2019/09/27
 */
public class SelfTimerTaskTwo extends TimerTask {

    private String jobName = "";

    SelfTimerTaskTwo(String jobName) {
        super();
        this.jobName = jobName;
    }

    @Override
    public void run() {
        System.out.println("execute " + jobName);
    }

    public static void main(String[] args) {
        long delay = 1000;
        ScheduledExecutorService scheduledExecutorService = Executors.newScheduledThreadPool(2);
        scheduledExecutorService.schedule(new SelfTimerTaskTwo("job1"), delay, TimeUnit.MILLISECONDS);
        delay = 2000;
        scheduledExecutorService.schedule(new SelfTimerTaskTwo("job2"), delay, TimeUnit.MILLISECONDS);
    }
}
